package web.User;

import com.google.gson.Gson;
import entity.RolesBean;
import services.RolesServiceAll;
import services.UserServiceAll;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updateUsersRoleId")
public class UpdateUsersRoleId extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        int uid = Integer.parseInt(req.getParameter("Uid"));
        String radioRolesCheckedName = req.getParameter("radioRolesChecked");
        int radioRolesCheckedId = new RolesServiceAll().getRoleIdByRoleName(radioRolesCheckedName);
        int num= new UserServiceAll().updateUsersRoleId(uid, radioRolesCheckedId);
        resp.getWriter().println(num);
    }
}
